﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SmartSpace.Core
{
    public class CoreSearcher : ICoreSearcher
    {
        public PagedResult<Privilege> FindPrivilege(string type, string name, string caption, int start, int limit)
        {
            using (CoreDbContext context = new CoreDbContext())
            {
                string sql = "select * from core_privilege where type like {0} and name like {1} and caption like {2}";
                List<Privilege> list = context.Database.SqlQuery<Privilege>(sql,
                    string.Format("%{0}%", type),
                    string.Format("%{0}%", name),
                    string.Format("%{0}%", caption)).Skip(start).Take(limit).ToList();

                int total = context.Database.SqlQuery<Privilege>(sql,
                    string.Format("%{0}%", type),
                    string.Format("%{0}%", name),
                    string.Format("%{0}%", caption)).Count();

                return new PagedResult<Privilege>(start, limit, total, list);
            }
        }
    }
}
